package com.ews.onlineexchange.controller;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.CodeDic;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.service.EntityQuery;
import org.apache.commons.lang3.StringUtils;

@Model
public class CodeDicList extends EntityQuery<CodeDic> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String codeName;
	private String codeValue;
	private String codeType;
	
	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<CodeDic> entity) {
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
	
		if(!StringUtils.isBlank(codeName)) {
			restrictions.add(cb.like(entity.<String>get("codeName"), getStringRestriction(codeName)));
		}
		if(!StringUtils.isBlank(codeValue)) {
			restrictions.add(cb.like(entity.<String>get("codeValue"), getStringRestriction(codeValue)));
		}
		if(!StringUtils.isBlank(codeType)) {
			restrictions.add(cb.like(entity.<String>get("codeType"), getStringRestriction(codeType)));
		}
		return restrictions;
	}

	public CodeDicList() {
		setOrder(" createDate desc,id");
		setMaxResults(10);
	}

	public String getCodeName() {
		return codeName;
	}

	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}

	public String getCodeValue() {
		return codeValue;
	}

	public void setCodeValue(String codeValue) {
		this.codeValue = codeValue;
	}

	public String getCodeType() {
		return codeType;
	}

	public void setCodeType(String codeType) {
		this.codeType = codeType;
	}
}
